import pygame
from pygame.locals import *
from spritesheet import *

class Hero(pygame.sprite.Sprite):
	def __init__(self, spritesheet):
		pygame.sprite.Sprite.__init__(self)
		
		self.direction = 2
		self.moving = (0, 0)
		
		self.image = pygame.surface.Surface((64, 64))
		self._images = spritesheet.get_image(Rect((0, 0), (256, 64)))
		self.rect = Rect((298, 298), (64, 64))
		self.health = 100
		
	def update(self, tiles):
		# 0 = north, 1 = east, 2 = south, 3 = west
		x, y = self.rect.left, self.rect.top
		if self.moving[1] == 1:
			if self.direction == 0:
				if y > 20:
					self.rect.move_ip(0, -2)
			elif self.direction == 2:
				if y < 556:
					self.rect.move_ip(0, 2)
		if self.moving[0] == 1:
			if self.direction == 1:
				if x < 556:
					self.rect.move_ip(2, 0)
			elif self.direction == 3:
				if x > 20:
					self.rect.move_ip(-2, 0)
			
		s_rect = Rect((self.direction * 64, 0), (64, 64))
		self.image.blit(self._images, (0, 0), s_rect)
		self.image.set_colorkey(self.image.get_at((0, 0)), RLEACCEL)
		